<?php
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

/* @var $block \Magento\Reports\Block\Product\Widget\Viewed\Item */
?>

<?php
$type = $block->getType() . '-' . $block->getViewMode();

$item = $block->getProduct();

$image = $block->getImageType();
$rating = 'short';
?>
<div class="block" id="widget_viewed_item" data-sku="<?php /* @escapeNotVerified */ echo $item->getSku(); ?>" style="display: none;">
    <li class="item product">
        <div class="product">
            <?php /* @escapeNotVerified */ echo '<!-- ' . $image . '-->' ?>
            <a href="<?php /* @escapeNotVerified */ echo $block->getProductUrl($item) ?>" class="product photo">
                <?php echo $block->getImage($item, $image)->toHtml(); ?>
            </a>
            <div class="product details">
                <strong class="product name"><a title="<?php echo $block->escapeHtml($item->getName()) ?>" href="<?php /* @escapeNotVerified */ echo $block->getProductUrl($item) ?>">
                    <?php echo $block->escapeHtml($item->getName()) ?></a>
                </strong>

                <?php /* @escapeNotVerified */ echo $block->getProductPriceHtml(
                    $item,
                    \Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE,
                    \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST,
                    [
                        'price_id_suffix' => '-' . $type
                    ]
                ) ?>

                <?php if ($rating): ?>
                    <?php echo $block->getReviewsSummaryHtml($item, $rating) ?>
                <?php endif; ?>

                <div class="product actions">
                    <div class="primary">
                        <?php if ($item->isSaleable()): ?>
                            <?php if ($item->getTypeInstance()->hasRequiredOptions($item)): ?>
                                <button class="action tocart" data-mage-init='{"redirectUrl": {"url": "<?php /* @escapeNotVerified */ echo $block->getAddToCartUrl($item) ?>"}}' type="button" title="<?php /* @escapeNotVerified */ echo __('Add to Cart') ?>">
                                    <span><?php /* @escapeNotVerified */ echo __('Add to Cart') ?></span>
                                </button>
                            <?php else: ?>
                                <?php $postDataHelper = $this->helper('Magento\Framework\Data\Helper\PostHelper');
                                $postData = $postDataHelper->getPostData($block->getAddToCartUrl($item), ['product' => $item->getEntityId()])
                                ?>
                                <button class="action tocart"
                                        data-post='<?php /* @escapeNotVerified */ echo $postData; ?>'
                                        type="button" title="<?php /* @escapeNotVerified */ echo __('Add to Cart') ?>">
                                    <span><?php /* @escapeNotVerified */ echo __('Add to Cart') ?></span>
                                </button>
                            <?php endif; ?>
                        <?php else: ?>
                            <?php if ($item->getIsSalable()): ?>
                                <div class="stock available"><span><?php /* @escapeNotVerified */ echo __('In stock') ?></span></div>
                            <?php else: ?>
                                <div class="stock unavailable"><span><?php /* @escapeNotVerified */ echo __('Out of stock') ?></span></div>
                            <?php endif; ?>
                        <?php endif; ?>
                    </div>

                    <div class="secondary-addto-links" data-role="add-to-links">
                        <?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow()): ?>
                            <a href="#" data-post='<?php /* @escapeNotVerified */ echo $block->getAddToWishlistParams($item); ?>'  class="action towishlist" data-action="add-to-wishlist" title="<?php /* @escapeNotVerified */ echo __('Add to Wish List') ?>">
                                <span><?php /* @escapeNotVerified */ echo __('Add to Wish List') ?></span>
                            </a>
                        <?php endif; ?>
                        <?php if ($block->getAddToCompareUrl()): ?>
                            <?php
                            $compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');
                            ?>
                            <a href="#" class="action tocompare"
                               data-post='<?php /* @escapeNotVerified */ echo $compareHelper->getPostDataParams($item);?>'
                               data-role="add-to-links"
                               title="<?php /* @escapeNotVerified */ echo __('Add to Compare'); ?>">
                                <span><?php /* @escapeNotVerified */ echo __('Add to Compare') ?></span>
                            </a>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>
    </li>
</div>
